package com.base.cn.platform.os.controller.user.login;

import com.base.cn.platform.os.common.constants.ConfigName;
import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.j2cache.CustomCacheChannel;
import com.base.cn.platform.os.common.j2cache.J2CacheRegion;
import com.base.cn.platform.os.common.md5.MD5;
import com.base.cn.platform.os.common.msg.WXTmpEnum;
import com.base.cn.platform.os.common.rsa.WebRsaUtils;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.Security.PurseSecurityUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.action.ActionKey;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.common.utils.sms.SmsSendUtils;
import com.base.cn.platform.os.common.utils.user.LoginForm;
import com.base.cn.platform.os.common.utils.user.ProfileType;
import com.base.cn.platform.os.common.utils.user.UserExpandFrom;
import com.base.cn.platform.os.entity.manage.subject.SysSubject;
import com.base.cn.platform.os.entity.op.giftcard.OpGiftCardCode;
import com.base.cn.platform.os.entity.user.user.CusUser;
import com.base.cn.platform.os.entity.user.user.CuserProfile;
import com.base.cn.platform.os.service.manage.config.SysConfigBiz;
import com.base.cn.platform.os.service.manage.subject.SysSubjectBiz;
import com.base.cn.platform.os.service.manage.user.integral.CusUserIntegralService;
import com.base.cn.platform.os.service.op.affiche.tmp.SendMessage;
import com.base.cn.platform.os.service.op.coupon.OpCouponCodeBiz;
import com.base.cn.platform.os.service.op.giftcard.OpGiftCardCodeBiz;
import com.base.cn.platform.os.service.user.integral.CusUserIntegralBiz;
import com.base.cn.platform.os.service.user.user.CusUserBiz;
import com.base.cn.platform.os.service.user.user.CuserProfileBiz;
import com.base.cn.platform.os.service.user.user.UserLoginBiz;
import com.base.cn.platform.os.service.user.user.ValidateUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * 学员登录
 *
 * @author s.li
 * @create 2018-06-01-16:23
 */
@RestController
@RequestMapping("/manage/user")
public class UserLoginController extends BaseController {

    @Autowired
    private UserLoginBiz userLoginBiz;
    @Autowired
    private CusUserBiz cusUserBiz;
    @Autowired
    private CuserProfileBiz cuserProfileBiz;
    @Autowired
    private OpGiftCardCodeBiz opGiftCardCodeBiz;
    @Autowired
    private ValidateUser validateUser;
    @Autowired
    private SysSubjectBiz sysSubjectBiz;
    @Autowired
    private SmsSendUtils smsSendUtils;
    @Autowired
    private SysConfigBiz sysConfigBiz;
    @Autowired
    private OpCouponCodeBiz opCouponCodeBiz;
    @Autowired
    private SendMessage sendMessage;
    @Autowired
    private CusUserIntegralService cusUserIntegralService;
    @Autowired
    private CusUserIntegralBiz cusUserIntegralBiz;
    /**
     * 不建议在controller中写
     */
    @Autowired
    private CustomCacheChannel customCacheChannel;

    /**
     * 后台强制退出学员登录
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/forceUserSignOut")
    public Map<String,Object> forceUserSignOut(@RequestParam("userId") BigDecimal userId){
        customCacheChannel.evict(J2CacheRegion.THIRTY_DAY_REGION.getKey(),userId.toString());
        return ResultUtil.SUCCESS("强制退出登录成功");
    }

    /**
     * 验证找回密码的手机号
     * @param mobile 手机号
     * @param mobileCode 短信验证码
     * @return Map<String,Object>
     */
    @RequestMapping("/verificationForgetMobileCode")
    public Map<String,Object> verificationForgetMobileCode(@RequestParam("mobile") String mobile,
                                                           @RequestParam("mobileCode") String mobileCode){
        if(StringUtils.isEmpty(mobile)){
            return ResultUtil.ERROR("请填写原绑定手机号");
        }
        if(!StringUtils.isMobile(mobile)){
            return ResultUtil.ERROR("请填写正确手机号");
        }
        if(StringUtils.isEmpty(mobileCode)){
            return ResultUtil.ERROR("请填写手机验证码");
        }
        TreeMap<String,String> configMap = sysConfigBiz.getSysConfigContext(ConfigName.SMS);
        smsSendUtils.setSmsConfig(configMap);
        boolean isOk = smsSendUtils.validateBackPwdCode(mobile,mobileCode);
        if(!isOk){
            return ResultUtil.ERROR("手机验证码错误");
        }
        return ResultUtil.SUCCESS("验证成功",mobileCode);
    }

    /**
     * 重新缓存用户登录信息
     * @param sessionId 缓存KEY
     * @param userStr 用户对象
     */
    @RequestMapping("/updateUserLoginCache")
    public void updateUserLoginCache(@RequestParam("sessionId") String sessionId,
                                     @RequestParam("userStr") String userStr){
        CusUser cusUser = gson.fromJson(userStr,CusUser.class);
        cusUser.setPassword(null);
        cusUser.setCustomerkey(null);
        String webUserStr = (String)customCacheChannel.get(J2CacheRegion.THIRTY_DAY_REGION.getKey(), sessionId).getValue();
        if(StringUtils.isNotEmpty(webUserStr)){
            customCacheChannel.set(J2CacheRegion.THIRTY_DAY_REGION.getKey(), sessionId, gson.toJson(cusUser));
        }
        webUserStr = (String)customCacheChannel.get(J2CacheRegion.ONE_DAY_REGION.getKey(), sessionId).getValue();
        if(StringUtils.isNotEmpty(webUserStr)){
            customCacheChannel.set(J2CacheRegion.ONE_DAY_REGION.getKey(), sessionId, gson.toJson(cusUser));
        }
    }

    /**
     * 学员登录
     * @param user    用户属性对象
     * @param client  登录终端（PC、MOBILE、APP、APPLET）
     * @param autoThirty 30天内自动登录
     * @param gapLeft 验证证图坐标
     * @param moveLeft 验证图移动坐标
     * @return Map<String,Object>
     */
    @RequestMapping("/userLogin")
    public Map<String, Object> userLogin(HttpServletRequest request,
                                         @RequestBody CusUser user,
                                         @RequestParam("client") String client,
                                         @RequestParam("autoThirty") String autoThirty,
                                         @RequestParam(value = "gapLeft",required = false,defaultValue = "0") String gapLeft,
                                         @RequestParam(value = "moveLeft",required = false,defaultValue = "0") String moveLeft)throws Exception{
        //验证登录方式
        if (!LoginForm.LOGIN_FROM_MOBILE.equals(client) &&
                !LoginForm.LOGIN_FROM_PC.equals(client) &&
                !LoginForm.LOGIN_FORM_APP.equals(client)) {
            return ResultUtil.ERROR("数据错误登录失败");
        }
        if (StringUtils.isEmpty(user.getLoginAccount())) {
            return ResultUtil.ERROR("请输入登录账号");
        }
        if (StringUtils.isEmpty(user.getPassword())) {
            return ResultUtil.ERROR("请输入登录密码");
        }
        if (LoginForm.LOGIN_FROM_PC.equals(client)) {
            gapLeft = WebRsaUtils.decrypt(customCacheChannel,user.getSign(),gapLeft,false);
            moveLeft = WebRsaUtils.decrypt(customCacheChannel,user.getSign(),moveLeft,false);
            if (!validateCode(Integer.parseInt(gapLeft), Integer.parseInt(moveLeft))) {
                return ResultUtil.ERROR("验证码错误");
            }
        }
        //开关配置
        TreeMap<String,String> onOffConfig = sysConfigBiz.getSysConfigContext(ConfigName.ONOFF);
        String loginSwitch = onOffConfig.get("loginSwitch");
        if(!"ON".equals(loginSwitch)){
            return ResultUtil.ERROR("因登录入口已关闭，登录失败");
        }
        CusUser loginUser = cusUserBiz.getLongUser(user.getLoginAccount());//查询用户数据
        boolean isUserCard = false;
        BigDecimal userCardId =null;
        //如果查询到的用户数据为空，再通过登录的账号查询学员卡
        if(ObjectUtils.isEmpty(loginUser)){
            //通过学员卡查询   礼品卡类型  1（学员卡）
            OpGiftCardCode userCard = opGiftCardCodeBiz.queryGiftCardCodeByCode(user.getLoginAccount(), 1);
            if (ObjectUtils.isNotEmpty(userCard)){
                //解密密码
                String password = WebRsaUtils.decrypt(customCacheChannel,user.getSign(),user.getPassword(),false);
                if (userCard.getCodePwd().equals(password)) {
                    loginUser = new CusUser();
                    loginUser.setLoginAccount(userCard.getCode());
                    loginUser.setPassword(userCard.getCodePwd());
                    loginUser.setRegisterFrom(UserExpandFrom.userCardFrom.getKey());
                    loginUser.setRegisterType(2);//非注册用户
                    //创建课程卡用户
                    loginUser = cusUserBiz.createUser(loginUser);
                    //学员卡的ID
                    userCardId = userCard.getId();
                    isUserCard =true;
                }else{
                    return ResultUtil.ERROR("密码错误");
                }
            }
        }
        //判断用户是否存在
        if (!ObjectUtils.isNotEmpty(loginUser)) {
            return ResultUtil.ERROR("账户或密码错误");
        }
        //解密密码
        String password = WebRsaUtils.decrypt(customCacheChannel,user.getSign(),user.getPassword(),true);
        //验证密码
        String _password = PurseSecurityUtils.secrect(password, loginUser.getCustomerkey());
        if (!_password.equals(loginUser.getPassword())) {
            return ResultUtil.ERROR("账户或密码错误");
        }
        //验证用户状态
        if (loginUser.getIsavalible() == 2) {
            return ResultUtil.ERROR("帐号已被冻结，暂不允许登录。<br>如有疑问，请联系客服。");
        }
        //未验证手机号，则完善用户资料后才可完成登录，
        //所以不正式设置用户信息到缓存，只是临时缓存1小时
        String sessionId = MD5.getMD5(StringUtils.getRandomString(32)+System.currentTimeMillis()+user.getId());
        Map<String,Object> resultMap = userLoginBiz.setUserCache(request,loginUser,sessionId,autoThirty,client);
        String status = (String)resultMap.get("status");
        //==================登录验证通过===============================
        if(StringUtils.isEmpty(status)){
            ResultUtil.setEntity(resultMap,loginUser);
        }
        //设置用户数据
        userLoginBiz.setUserLoginInfo(loginUser,isUserCard,userCardId);
        return resultMap;
    }

    /**
     * 注册用户
     * @param user 用户对象
     * @param loginForm 登录来源
     * @return
     */
    @RequestMapping("/toRegister")
    public Map<String,Object> toRegister(HttpServletRequest request,@RequestBody  CusUser user,
                                         @RequestParam("loginForm") String loginForm)throws Exception{
        Map<String,Object> _map = validateUser.vUserData(user);
        if (!ObjectUtils.isNotEmpty(_map)){
            user.setConfirmPwd(null);
            user.setMobileCode(null);
            //设置默认登录次数为1
            user.setLoginNum(1);
            user = cusUserBiz.createUser(user);
            if (user.getStatus() != 0) {
                cusUserIntegralService.addUserIntegral(ActionKey.REGISTER, user.getId(), null, 0, 2);
            }
            //发送消息
            sendMessage.sendMessage(WXTmpEnum.REGISTER, Arrays.asList(user.getId()),null);

            user.setPassword(null);
            user.setCustomerkey(null);
            //赠送注册优惠券
            opCouponCodeBiz.giveUserRegCouponCode(user.getId());

            //生成KEY
            String sessionId = MD5.getMD5(StringUtils.getRandomString(32)+System.currentTimeMillis()+user.getId());
            //缓存用户
            Map<String,Object> resultMap = userLoginBiz.setUserCache(request,user,sessionId,"false",loginForm);
            String status = (String) resultMap.get("status");
            if(StringUtils.isEmpty(status)){
                ResultUtil.setEntity(resultMap,user);
            }
            ResultUtil.setMessage(resultMap,"注册成功");

            if(ResultUtil.getSuccess(resultMap)){
                cusUserIntegralBiz.inviterDealWith(user.getInviteKey(),user.getId());
            }
            //最后再删除验证码
            TreeMap<String,String> configMap = sysConfigBiz.getSysConfigContext(ConfigName.SMS);
            smsSendUtils.setSmsConfig(configMap);
            //删除验证码缓存
            smsSendUtils.removeRegCode(user.getMobile());
            return resultMap;
        }
        return _map;
    }

    //======================================完善用户资料，开始============================
    /**
     * 设置学员专业
     * @param sessionId 用户缓存KEY
     * @param parentId 专业ID
     * @param childIds 科目ID串
     * @param autoThirty 缓存30天
     * @param loginForm 登录来源
     * @return Map<String,Object>
     */
    @RequestMapping("/setUserSubjectIds")
    public Map<String,Object> setUserSubjectIds(HttpServletRequest request,
                                                @RequestParam("sessionId") String sessionId,
                                                @RequestParam("parentId") BigDecimal parentId,
                                                @RequestParam("childIds") String childIds,
                                                @RequestParam("autoThirty") String autoThirty,
                                                @RequestParam("loginForm") String loginForm)throws IOException {
        CusUser cusUser = (CusUser)customCacheChannel.get(J2CacheRegion.ONE_HOURS_REGION.getKey(),sessionId).getValue();
        if(ObjectUtils.isEmpty(cusUser)){
            return ResultUtil.ERROR("数据错误，设置专业/科目数据失败");
        }
        if(!DataUtil.idIsNotNull(parentId)){
            return ResultUtil.ERROR("请选择一个专业");
        }
        if(StringUtils.isEmpty(childIds)){
            return ResultUtil.ERROR("请选择一个或多个科目");
        }
        String subjectIds = parentId+","+childIds;
        SysSubject sysSubject = new SysSubject();
        sysSubject.setQueryIds(subjectIds);
        List<SysSubject> subjectList = sysSubjectBiz.findSubjectList(sysSubject);
        if(subjectIds.split(",").length != subjectList.size()){
            return ResultUtil.ERROR("专业/科目数据错误");
        }
        //重新查询
        CusUser _cusUser = cusUserBiz.findById(cusUser.getId());
        //更新专业
        _cusUser = cusUserBiz.updateUserNaturalSubjectIds(_cusUser,subjectIds);
        //重新设置是否是第三方登录标识和是否需要设置密码标识
        _cusUser.setOther(cusUser.isOther());
        _cusUser.setCpId(cusUser.getCpId());
        _cusUser.setAdministrator(cusUser.isAdministrator());
        Map<String,Object> resultMap = userLoginBiz.setUserCache(request,_cusUser,sessionId,autoThirty,loginForm);
        String status = (String) resultMap.get("status");
        if(StringUtils.isEmpty(status)){
            ResultUtil.setMessage(resultMap,"专业设置成功");
            ResultUtil.setEntity(resultMap,cusUser);
        }
        return resultMap;
    }


    /**
     * 完善资料，设置用户手机号
     * @param sessionId 用户缓存KEY
     * @param mobile 绑定的手机号
     * @param mobileCode 手机验证码
     * @param autoThirty 缓存30天
     * @param loginForm 登录来源
     * @return Map<String,Object>
     */
    @RequestMapping("/setUserMobile")
    public Map<String,Object> setUserMobile(HttpServletRequest request,
                                            @RequestParam("sessionId") String sessionId,
                                            @RequestParam("mobile") String mobile,
                                            @RequestParam("mobileCode") String mobileCode,
                                            @RequestParam("autoThirty") String autoThirty,
                                            @RequestParam("loginForm") String loginForm)throws IOException{
        CusUser cusUser = (CusUser) customCacheChannel.get(J2CacheRegion.ONE_HOURS_REGION.getKey(),sessionId).getValue();
        if(ObjectUtils.isEmpty(cusUser)){
            return ResultUtil.ERROR("数据错误，完善资料败");
        }
        if(!StringUtils.isMobile(mobile)){
            return ResultUtil.ERROR("请填写正确的手机号");
        }
        if(StringUtils.isEmpty(mobileCode)){
            return ResultUtil.ERROR("请输入手机验证码");
        }
        TreeMap<String,String> configMap = sysConfigBiz.getSysConfigContext(ConfigName.SMS);
        smsSendUtils.setSmsConfig(configMap);
        boolean codeStatus = smsSendUtils.validateUserInfoCode(mobile,mobileCode);
        if(!codeStatus){
            return ResultUtil.ERROR("验证码错误");
        }
        CusUser _user;
        if(cusUser.isOther() && DataUtil.idIsNotNull(cusUser.getCpId()) && cusUser.getStatus()==0){//如果是第三方登录
            CuserProfile cuserProfile = cuserProfileBiz.findById(cusUser.getCpId(),null);
            if(ObjectUtils.isEmpty(cuserProfile)){
                return ResultUtil.ERROR("第三方登录记录数据不存在");
            }
            //通过手机查询用户对象
            _user = cusUserBiz.queryUserByMobile(mobile);
            if(ObjectUtils.isEmpty(_user)){//如果手机未被使用过
                _user = cusUserBiz.findById(cusUser.getId());
                _user.setMobileIsavalible(1);
                _user.setMobile(mobile);
                _user.setStatus(1);
                cusUserBiz.updateById(_user,null);
                _user.setOther(cusUser.isOther());
                _user.setCpId(cusUser.getCpId());
                if(cusUser.isOther() && DataUtil.idIsNotNull(cusUser.getCpId())){//需要设置密码
                    _user.setAdministrator(true);
                }
            }else{//手机已被使用
                CuserProfile profile = new CuserProfile();
                profile.setProfileType(cuserProfile.getProfileType());
                profile.setUserId(_user.getId());
                CuserProfile _profile = cuserProfileBiz.findCuserProfile(profile);
                if(_profile !=null){
                    if(cuserProfile.getProfileType().equals(ProfileType.WEIXIN.toString())){
                        return ResultUtil.ERROR("该手机已绑定过微信号");
                    }
                    if(cuserProfile.getProfileType().equals(ProfileType.QQ.toString())){
                        return ResultUtil.ERROR("该手机已绑定过QQ号");
                    }
                }
                //修改第三方登录记录绑定的用户
                cuserProfileBiz.updateCuserProfileBindingUser(cuserProfile,_user.getId());
            }
        }else{//不是第三方登录账号，或原来绑定关闭绑定手机号后来开放的
            _user = cusUserBiz.queryUserByMobile(mobile);
            if(ObjectUtils.isNotEmpty(_user)){
                return ResultUtil.ERROR("手机号已被使用");
            }
            _user = cusUserBiz.findById(cusUser.getId());
            if(StringUtils.isEmpty(_user.getMobile())){
                _user.setMobile(mobile);
                _user.setMobileIsavalible(1);
                cusUserBiz.updateById(_user,null);
                CuserProfile condition = new CuserProfile();
                condition.setUserId(_user.getId());
                CuserProfile profile = cuserProfileBiz.findCuserProfile(condition);
                if(profile !=null){//需要设置密码
                    _user.setAdministrator(true);
                }
            }
        }
        Map<String,Object> resultMap = userLoginBiz.setUserCache(request,_user,sessionId,autoThirty,loginForm);
        //删除验证码
        if(ResultUtil.getSuccess(resultMap)){
            smsSendUtils.removeUserInfoCode(mobile);
            String status = (String)resultMap.get("status");
            ResultUtil.setMessage(resultMap,"手机号绑定成功");
            if(StringUtils.isEmpty(status)){
                ResultUtil.setEntity(resultMap,_user);
            }
        }
        return resultMap;
    }

    /**
     * 设置登录密码
     * @param userId 用户ID
     * @param userPassword 用户密码
     * @param confirmPassword 用户砍确认密码
     * @return Map<String,Object>
     */
    @RequestMapping("/setPerfectPwd")
    public Map<String,Object> setPerfectPwd(@RequestParam("userId") BigDecimal userId,
                                            @RequestParam("userPassword") String userPassword,
                                            @RequestParam("confirmPassword") String confirmPassword,
                                            @RequestParam("sign") String sign) throws Exception{
        CusUser cusUser = cusUserBiz.findById(userId);
        if(ObjectUtils.isEmpty(cusUser)){
            return ResultUtil.ERROR("用户不存在");
        }
        if(StringUtils.isEmpty(userPassword)){
            return ResultUtil.ERROR("请输入登录密码");
        }
        //解密密码
        userPassword = WebRsaUtils.decrypt(customCacheChannel,sign,userPassword,false);
        confirmPassword = WebRsaUtils.decrypt(customCacheChannel,sign,confirmPassword,true);
        Map<String,Object> result = validateUser.validatePwd(userPassword);
        if(result !=null){
            return result;
        }
        if(!userPassword.trim().equals(confirmPassword.trim())){
            return ResultUtil.ERROR("两次密码不一致");
        }
        //执行重置密码
        cusUserBiz.resetPassword(cusUser.getId(),userPassword);
        return ResultUtil.SUCCESS("登录密码设置成功");
    }
    //======================================完善用户资料，结束============================

    //============================================找回密码，开始==========================

    /**
     * 密码找回重置
     * @param mobile 手机号
     * @param mobileCode 手机验证码
     * @param password 密码
     * @param confirmPwd 确认密码
     * @return Map<String,Object>
     */
    @RequestMapping("/retrievePwd")
    public Map<String,Object> retrievePwd(@RequestParam("mobile") String mobile,
                                          @RequestParam("mobileCode") String mobileCode,
                                          @RequestParam("password") String password,
                                          @RequestParam("confirmPwd") String confirmPwd,
                                          @RequestParam("sign") String sign) throws Exception{
        if(StringUtils.isEmpty(mobile)){
            return ResultUtil.ERROR("请输入手机号");
        }
        if(!StringUtils.isMobile(mobile)){
            return ResultUtil.ERROR("请填写正确的手机号");
        }
        if(StringUtils.isEmpty(mobileCode)){
            return ResultUtil.ERROR("请输入手机验证码");
        }
        TreeMap<String,String> configMap = sysConfigBiz.getSysConfigContext(ConfigName.SMS);
        smsSendUtils.setSmsConfig(configMap);
        boolean isOk = smsSendUtils.validateBackPwdCode(mobile,mobileCode);
        if(!isOk){
            return ResultUtil.ERROR("手机验证码错误");
        }
        //解密密码
        password = WebRsaUtils.decrypt(customCacheChannel,sign,password,false);
        confirmPwd = WebRsaUtils.decrypt(customCacheChannel,sign,confirmPwd,true);
        Map<String,Object> result = validateUser.validatePwd(password);
        if(result !=null){
            return result;
        }
        if(!password.trim().equals(confirmPwd.trim())){
            return ResultUtil.ERROR("两次密码不一致");
        }
        CusUser _user = cusUserBiz.queryUserByMobile(mobile);
        if(ObjectUtils.isEmpty(_user)){
            return ResultUtil.ERROR("该手机号未注册过");
        }
        //执行重置密码
        cusUserBiz.resetPassword(_user.getId(),password);
        //删除验证码
        smsSendUtils.removeBackPwdCode(mobile);
        return ResultUtil.SUCCESS("密码重置成功");
    }
    //============================================找回密码，结束==========================

    /**
     * 退出登录
     * @param sessionId 会话ID
     * @param userId 用户ID
     * @return true退出成功，false退出失败
     */
    @RequestMapping("/signOut")
    public boolean signOut(@RequestParam("sessionId") String sessionId,
                           @RequestParam("userId") BigDecimal userId){
        if(StringUtils.isNotEmpty(sessionId) && DataUtil.idIsNotNull(userId)){
            customCacheChannel.evict(J2CacheRegion.THIRTY_DAY_REGION.getKey(),sessionId);
            customCacheChannel.evict(J2CacheRegion.ONE_DAY_REGION.getKey(),sessionId);
            return true;
        }
        return false;
    }

    /**
     * 设置用户登录Token
     * @param userId 用户ID
     * @param sessionId 用户登录Token
     */
    @RequestMapping("/setUserToken")
    public void setUserToken(@RequestParam("userId") BigDecimal userId,@RequestParam("sessionId") String sessionId){
        userLoginBiz.setUserToken(userId,sessionId);
    }
    //=========================================================
    /**
     * 验证图片验证码
     * @param gapLeft 固定图片坐标
     * @param moveLeft 移动图片坐标
     * @return false验证不通过，true验证通过
     */
    private boolean validateCode(int gapLeft,int moveLeft){
        int dvalue = 5;
        int v = Math.abs(gapLeft - moveLeft);
        if(gapLeft==0 || moveLeft==0 || v > dvalue){
            return false;
        }
        return true;
    }
}
